/*
 * Copyright 2009 Max Kugland
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.splink.deepsplink.page.operation {
	import org.splink.deepsplink.page.IPageInternal;
	import org.splink.library.distributor.Distributor;
	import org.splink.library.queue.QEvent;

	/**
	 * An <code>IPageOperation</code> implementation which injects the page parameters into 
	 * an <code>IPage</code>
	 * 
	 * @author Max Kugland
	 */
	final public class PageParamsOperation extends Distributor implements IPageOperation {
		private var _page : IPageInternal;
		private var _params : Array;

		public function PageParamsOperation(page : IPageInternal, params : Array) {
			_page = page;
			_params = params;
		}

		/**
		 * @inheritDoc
		 */
		public function get id() : String {
			return _page.id;
		}

		/**
		 * @inheritDoc
		 */
		public function start() : void {
			_page.setParams(_params.concat());
			distribute(new QEvent(this, QEvent.COMPLETE, id));
		}

		/**
		 * @inheritDoc
		 */
		override public function finalize() : void {
			super.finalize();
			_page = null;
			_params = null;
		}

		/**
		 * @inheritDoc
		 */
		public function stop() : void {
		}

		/**
		 * @inheritDoc
		 */
		public function reset() : void {
		}
	}
}
